package com.wise.service.cms.content.advice;

import com.wise.entities.content.SearchAdvice;
import com.wise.framework.basic.DateTimeUtil;
import com.wise.framework.daomodel.DaoOne4Update;
import com.wise.framework.daomodel.DaoSave;
import com.wise.framework.session.CurrentUserId;
import com.wise.summer.v1.cms.content.advice.UpdateAdvice;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import static com.wise.model.content.ContentErrMsgs.Err_001000250047;

/**
 * 修改推荐推荐搜索关键字-链接
 *
 * @author Haoming Chen
 * Created on 2019/11/14
 */
@Service
@SummerService
public class UpdateAdviceService implements SummerServiceBean<UpdateAdvice> {

    @Override
    public void sum(UpdateAdvice model) {

        SearchAdvice searchAdvice = DaoOne4Update.s(SearchAdvice.class, model.getId(), Err_001000250047);
        searchAdvice.setLastUpdateBy(CurrentUserId.s(true));
        searchAdvice.setLastUpdateDate(DateTimeUtil.timestampNow());
        if (StringUtils.isNotBlank(model.getUri())) {
            searchAdvice.setUri(model.getUri());
        }
        if (StringUtils.isNotBlank(model.getKeyword())) {
            searchAdvice.setKeyword(model.getKeyword());
        }
        if (model.getSort() != null) {
            searchAdvice.setSort(model.getSort());
        }
        if (model.getIsActivate() != null) {
            searchAdvice.setIsActivate(model.getIsActivate() == 1 ? true : false);
        }
        DaoSave.s(searchAdvice);
        model.setSummerResult(true);

    }

}
